const express = require('express');

const app = express();

// express.static 托管静态资源
// express.json 解析json格式的请求体
// express.urlencoded 解析urlencoded格式的请求体

// 解析JSON
app.use(express.json())

// 解析表单数据
app.use(express.urlencoded({
  extended: false
}))

// 托管静态资源
app.use('/aaa', express.static('./static'));

app.post('/user', (req, res) => {
  // 不配置解析json 默认是undefined
  console.log(req.body);
  
  res.send('Hello World!');
});

app.post('/form', (req, res) => {
  console.log(req.body);
  res.send('Hello World!');
});

app.listen(3000, () => {
  console.log('Server listening on port 3000');
});